import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class Test5 {

    private static AndroidDriver<AndroidElement> driver;
//搜索联系人
    public static void main(String[] args) {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "127.0.0.1:62001");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("noReset", true);
        capabilities.setCapability("appPackage", "com.cnezsoft.xxm");
        capabilities.setCapability("appActivity", ".MainActivity");

        try {
            URL appiumUrl = new URL("http://localhost:4723/wd/hub");
            driver = new AndroidDriver<>(appiumUrl, capabilities);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

            // 进入联系人列表页
            MobileElement contactTab = driver.findElement(By.xpath("//android.widget.TextView[@text='通讯录']"));
            contactTab.click();

            // 搜索联系人
            MobileElement searchBox = driver.findElement(By.xpath("//android.widget.EditText[@text='搜索']"));
            searchBox.sendKeys("li");

           

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }
    }
}
